package com.fuershiye.woman.monitor.dao.admin;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.fuershiye.woman.monitor.dao.HibernateDao;
import com.fuershiye.woman.monitor.model.Role;

@Repository("adminRoleDao")
public class RoleDao {

    @Autowired
    private HibernateDao hibernateDao;

    public void save(Role role){
        hibernateDao.save(role);
    }

    @SuppressWarnings("unchecked")
	public List<Role> list() {
        String hql = "from Role";
        Query query = hibernateDao.getQuery(hql);
        return query.list();
    }

    @SuppressWarnings("unchecked")
	public List<Role> listByName(String name) {
        String hql = "from Role where name like:name";
        Query query = hibernateDao.getQuery(hql);
        query.setString("name","%" + name + "%");
        return query.list();
    }

    public Role get(Long id) {
        return hibernateDao.getById(Role.class,id);
    }

    public void delete(Long id) {
        String hql = "delete Role where id=:id";
        Query query = hibernateDao.getQuery(hql);
        query.setLong("id",id);
        query.executeUpdate();
    }
}
